package com.sm.binder;

/**
 * Author: Sergejs Melderis
 */
public class DebugMessage {

    static final String COLUMN_TO_CONSTRUCTOR =
            " % column named % of type % bound to the % parameter of constructor of %";


    static final String COLUMN_TO_METHOD =
        " % column named % of type % bound to %";

    static final String COLUMN_NOT_BOUND =
            "<<<!!! % column named % of type % is not bound !!!>>>";

    private StringBuilder message = new StringBuilder();


    public DebugMessage(String message, Object... messageParameters) {
        String []parts = message.split("%");
        int i;
        for (i = 0; i < parts.length; i++) {
            this.message.append(parts[i]);
            String messageParamStr = null;
            if (i < messageParameters.length) {
                if (messageParameters[i] instanceof Integer) {
                    int val = (Integer) messageParameters[i];
                    switch (val) {
                        case 1:
                            messageParamStr = "first";
                            break;
                        case 2:
                            messageParamStr = "second";
                            break;
                        case 3:
                            messageParamStr = "third";
                            break;
                        default:
                            messageParamStr = val + "th";
                    }
                }

                this.message.append(messageParamStr == null
                                    ? messageParameters[i]
                                    : messageParamStr);
            }
        }

    }

    public String toString() {
        return message.toString();
    }

}
